export default {
    // 生成16位数的随机数
    randomNumber() {
        let chars = '0123456789qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM';
        let maxPos = chars.length;
        let str = '';
        for (let i = 0; i < 16; i++) {
            str += chars.charAt(Math.floor(Math.random() * maxPos));
        }
        return str;
    },
    // obj 转 params字符串参数  
    objParseParam(obj) {
        let paramsStr = "";
        if (obj instanceof Array) return paramsStr;
        if (!(obj instanceof Object)) return paramsStr;
        for (let key in obj) {
            paramsStr += `${key}=${obj[key]}&`;
        }
        return paramsStr.substring(0, paramsStr.length - 1);
    },
    /**
 * 根据文件url获取文件名
 * @param url 文件url
 */
    getFileName(url) {
        const num = url.lastIndexOf('/') + 1
        let fileName = url.substring(num)
        //把参数和文件名分割开
        fileName = decodeURI(fileName.split('?')[0])
        return fileName
    }
}